import request from '@/utils/request'

// 查询钓友圈帖子列表
export function listCommunityPost(query) {
  return request({
    url: '/pond/app/community/posts',
    method: 'get',
    params: query
  })
}

// 查询钓友圈帖子详细
export function getCommunityPost(id) {
  return request({
    url: '/pond/app/community/posts/' + id,
    method: 'get'
  })
}

// 新增钓友圈帖子
export function addCommunityPost(data) {
  return request({
    url: '/pond/app/community/posts',
    method: 'post',
    data: data
  })
}

// 修改钓友圈帖子
export function updateCommunityPost(data) {
  return request({
    url: '/pond/app/community/posts',
    method: 'put',
    data: data
  })
}

// 删除钓友圈帖子
export function delCommunityPost(ids) {
  return request({
    url: '/pond/app/community/posts/' + ids,
    method: 'delete'
  })
}

// 置顶/取消置顶帖子
export function toggleTop(id, isTop) {
  return request({
    url: '/pond/app/community/posts',
    method: 'put',
    data: {
      id: id,
      isTop: isTop
    }
  })
}

// 修改帖子状态
export function changeStatus(id, status) {
  return request({
    url: '/pond/app/community/posts',
    method: 'put',
    data: {
      id: id,
      status: status
    }
  })
}

// 获取热门帖子
export function getHotPosts(limit, type) {
  return request({
    url: '/pond/app/community/posts/hot',
    method: 'get',
    params: {
      limit: limit,
      type: type
    }
  })
}

// 获取帖子评论列表
export function getPostComments(postId) {
  return request({
    url: '/pond/app/community/posts/' + postId + '/comments',
    method: 'get'
  })
}

// 删除评论
export function deleteComment(commentId) {
  return request({
    url: '/pond/app/community/posts/comment/' + commentId,
    method: 'delete'
  })
}

// 上传图片 (使用系统统一的OSS上传接口)
export function uploadImage(file) {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/file/upload/oss',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}